import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  // createRouter 创建路由实例，===> new VueRouter()
// history 是路由模式，hash模式，history模式
// createWebHistory() 是开启history模块   http://xxx/user
// createWebHashHistory() 是开启hash模式    http://xxx/#/user

// vite 的配置 import.meta.env.BASE_URL 是路由的基准地址，默认是 ’/‘
// https://vitejs.dev/guide/build.html#public-base-path
// 如果将来你部署的域名路径是：http://xxx/my-path/user
// vite.config.ts  添加配置  base: my-path，路由这就会加上 my-path 前缀了
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path:'/login',
      component: () => import('@/views/login/index.vue'),
      name:'login'
    },
    {
      path:'/',
      redirect:{name:'404'}
    },
    {
      path:'/layout',
      component: () => import('@/views/layout/index.vue'),
      name:'layout',
      redirect:{name:'home'},
      children: [
        {
          path:'/home',
          component: () => import('@/views/home/index.vue'),
          name: 'home',
          meta:{title:'首页'}
        },
        {
          path:'/notify',
          component: () => import('@/views/Notify/index.vue'),
          name:'notify',
          meta:{title:'消息通知'}
        },
        {
          path:'/user',
          component: () => import('@/views/User/index.vue'),
          name:'user',
          meta:{title:'个人中心'}
        },
        {
          path:'/article',
          component: () => import('@/views/article/index.vue'),
          name: 'article',
          meta:{title:'健康百科'}
        },
      ]
    },
    {
      path:'/set',
      component:()=>import('@/views/User/set.vue'),
      name:'set'
    },
    {
      path:'/user/patient',
      component:()=>import('@/views/User/PatientPage.vue'),
      name:'patient'
    },{
      path:'/404',
      component:()=>import('@/views/404.vue'),
      name:'404'
    },
    {
      path:'/consult/fast',
      component:()=>import('@/views/consult/consultFast.vue'),
      name:'consultFast'
    },
    {
      path:'/consult/dep',
      component:()=>import('@/views/consult/consultDep.vue'),
      name:'consultDep'
    },
    {
      path: '/consult/illness',
      component:()=>import('@/views/consult/consultIllness.vue'),
      meta: { title: '病情描述' }
    },{
      path:'/consult/pay',
      component:()=>import('@/views/consult/consultPay.vue'),
      meta:{title:'问诊支付'},
      name:'consultPay'
    },
    {
      path: '/room',
      component: () => import('@/views/Room/index.vue'),
      meta: { title: '问诊室' },
      beforeEnter(to) {
        if (to.query.payResult === 'false') return '/user/consult'
      }
    },
    {
      path: '/user/consult',
      component:() => import('@/views/User/ConsultOrder.vue'),
      name:'ConsultOrder',
      meta:{title:'问诊订单'}
    },
    {
      path:'/user/consult/:id',
      component:()=>import('@/views/User/ConsultDetail.vue'),
      name:'ConsultDetail',
      meta:{title:'问诊详情'}
    },
    {
      path: '/medicine/pay',
      component: () => import('@/views/medicine/orderPay.vue'),
      meta: { title: '药品支付' }
    },
    {
      path: '/order/pay/result',
      component: () => import('@/views/medicine/orderPayResult.vue'),
      meta: { title: '药品支付结果' }
    },
    {
      path:'/order/:id',
      component:()=>import('@/views/medicine/OrdDetail.vue'),
      meta: { title: '订单详情' }
    },
    {
      path:'/medicine/express/:id',
      component:()=>import('@/views/medicine/express.vue'),
      meta: { title: '物流信息' }
    }
  ]
})

export default router
